// pages/classify/index.js
var imageUtil=require('../../utils/util.js');
const App = getApp()
var loadMore=function(that,page,pid,product_type){
  that.setData({
             hidden:false
     });
    wx.request({
      url: 'https://www.sjwwljs.cn/index.php/api/Classify/getClassifyDetail_list',
      data: {
        page:page,
        pid:pid,
        product_type:product_type
      },
      method: 'POST', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
      header: {
            'content-type': 'application/json'
      },
      success: function(res){
        if(res.data.mate.code==0){
          var dataList_=that.data.dataList
          for(var i=0;i<res.data.list.length;i++){
            dataList_.push(res.data.list[i])
          }
          that.setData({
             dataList : dataList_
            })
            
            that.setData({
                 hidden:true,
                 page:that.data.page+12
            });
        }
      },
    })
}

Page({
  data:{
    imagewidth:0,
    imageheight:0,
    curNav:0,
    neNav:0,
    selectId:0,
    scrollTop:0,
    hidden:true,
    systemHeight:0,
    pid:0,
    page:0,
    product_type:0,
    dataList:[],
    beiJin:[],
    zhShi:[],
    nextShi:[],
    liNav:999999
  },
  onLoad:function(){
    var that=this
    wx.getSystemInfo({
      success: function(res) {
        that.setData({
          systemHeight:res.windowHeight
        })
      }
    })
    this.getClassify();
  },
  onShow:function(){
    this.setData({
      selectId:0,
    curNav:0,
    neNav:0,
    pid:0,
    page:0,
    product_type:0,
    dataList:[],
    beiJin:[],
    zhShi:[],
    nextShi:[],
    liNav:999999
    })
    this.getClassify()
  },
  getClassify:function(){
     var that=this
     wx.showToast({
      title: '加载中',
      icon: 'loading',
      duration: 10000
    })
      App.HttpService.getClassify().then(data => {
            if (data.mate.code == 0) {
              wx.hideToast()
               loadMore(that,0,data.bei_jin[0]['id'],data.bei_jin[0]['product_type']);
                that.setData({
                    beiJin:data.bei_jin,
                    pid:data.bei_jin[0]['id'],
                    product_type:data.bei_jin[0]['product_type'],
                    zhShi:data.zh_shi
                })
                
            }
        })
  },
  imageLoad:function(e){
    var iamge =imageUtil.imagesSuo(e,250,250)
    this.setData({  
      imagewidth: iamge.imageWidth,  
      imageheight: iamge.imageHeight  
    })  
  },
  switchRightTab:function(e){
       let id = e.target.dataset.id,
			     index = parseInt(e.currentTarget.dataset.index);

            this.setData({
              curNav: index,
              selectId:0,
              liNav:9999999999
              //curIndex: index
            })
        var that = this;
        that.setData({
          pid:e.currentTarget.dataset.id,
          product_type:e.currentTarget.dataset.product,
          page:0,
          dataList:[]
        })
       loadMore(that,that.data.page,e.currentTarget.dataset.id,e.currentTarget.dataset.product); 
  },

  switchNextRightTable:function(e){
       let id = e.target.dataset.id,
			     selectId = parseInt(e.currentTarget.dataset.pid),
           index=parseInt(e.currentTarget.dataset.index);

            this.setData({
              curNav: 99999999,
              selectId:selectId,
              liNav:index
              //curIndex: index
            })
        var that = this;
        that.setData({
          pid:e.currentTarget.dataset.id,
          product_type:e.currentTarget.dataset.product,
          page:0,
          dataList:[]
        })
       loadMore(that,that.data.page,e.currentTarget.dataset.id,e.currentTarget.dataset.product); 
  },

  //点击查看照片
  showImageDetail:function(e){
    var id=e.currentTarget.dataset.id
    var src=encodeURIComponent(e.currentTarget.dataset.src)
    var product_type=e.currentTarget.dataset.product
    wx.navigateTo({
      url: '../classify/detail/index?id='+id+'&src='+src+'&product='+product_type,
    })
  },
    scroll:function(event){
        this.setData({
            scrollTop : event.detail.scrollTop
        });
    },
    //页面滑动到底部
   bindDownLoad:function(){   
       var that = this;
       loadMore(that,that.data.page,that.data.pid,that.data.product_type);
   },
    onPullDownRefresh:function(){
        this.onLoad()
    },
    isShow:function(e){
      this.setData({
        selectId:e.currentTarget.dataset.id,
        curNav:999999999,
        liNav:9999999999
      })
    }
})